package com.smt.threenationkill.tag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import com.smt.threenationkill.domain.ByRole;
import com.smt.threenationkill.domain.GameStat;
import com.smt.threenationkill.domain.Player;
import com.smt.threenationkill.enums.Result;
import com.smt.threenationkill.enums.Role;

public class NumTag extends SimpleTagSupport{

	private ByRole player;
	private Role role;
	private Result result;
	
//	public void setPlayer(Player player) {
//		this.player = player;
//	}
	
//	public void setPlayer(GameStat player) {
//		this.player = player;
//	}
	
	public void setPlayer(ByRole player) {
		this.player = player;
	}

	public void setRole(String role) {
		this.role = Role.valueOf(role);
		if (this.role == null){
			throw new IllegalArgumentException("Unknown role:"+role);
		}
	}
	
	public void setResult(String result) {
		this.result = Result.valueOf(result);
		if (this.result == null){
			throw new IllegalArgumentException("Unknown result:"+result);
		}
	}

	public void doTag() throws JspException, IOException{
		String print = "";
		if (result == Result.WON){
			print = String.valueOf(player.getGameNumWonByRole(role));	
		}else if(result == Result.LOST){
			print = String.valueOf(player.getGameNumPlayedByRole(role) 
					- player.getGameNumWonByRole(role));
		}
		getJspContext().getOut().print(print);
	}
	
}
